<script>

import * as echarts from 'echarts';
import "echarts-wordcloud/dist/echarts-wordcloud";
import "echarts-wordcloud/dist/echarts-wordcloud.min";

// import $ from 'jquery'
export default {
  name: 'VisualizationEleven',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data1', {}).then(res => {
        if (res.data.code === 20041) {
          let data = [];
          for (let i = 0; i < res.data.data.length; i++) {
            data.push(
                {
                  name:  res.data.data[i].param1,
                  value:  res.data.data[i].param2,
                },
            );
          }
          this.init(data);
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data) {
      var chartDom = document.getElementById('main11');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        tooltip: {
          show: true,
          // formatter: (params) => {
          //     const { name, value } = params;
          //     return `${name}:${value}`;
          // },
        },

        series: [
          {
            type: 'wordCloud',
            //size: ['9%', '99%'],
            sizeRange: [14, 50],
            //textRotation: [0, 45, 90, -45],
            rotationRange: [-45, 90],
            shape: 'circle',
            textPadding: 0,
            width: '80%',
            // 画布高
            height: '80%',
            autoSize: {
              enable: true,
              minSize: 6,
            },
            textStyle: {
              normal: {
                color: function () {
                  return (
                      'rgb(' +
                      [Math.round(Math.random() * 256), Math.round(Math.random() * 256), Math.round(Math.random() * 256)].join(
                          ','
                      ) +
                      ')'
                  );
                },
              },
              emphasis: {
                shadowBlur: 2,
                shadowColor: '#333',
              },
            },
            data: data,
          },
        ],
      };


      option && myChart.setOption(option);
    }
  }

}
</script>

<template>
  <div id="main11"></div>
</template>

<style scoped>
#main11 {
  width: 100%;
  height: 100%;
}
</style>